home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Borland Plateform / Turbo Pascal V7.0 / TVFM.ZIP / TVFM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-30  |  5.4 KB  |  230 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision File Manager Demo               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. {$M 16384,8192,655360}
  9. {$X+,V-}
  10.  
  11. program TVFM;
  12.  
  13. uses Objects, Drivers, Memory, App, Views, Menus, Dialogs, StdDlg, Globals,
  14.   Dos, MsgBox, Equ, Tools, TreeWin, Colors, Assoc, Trash, FileFind;
  15.  
  16. { If you get a FILE NOT FOUND error when compiling this program
  17.   from a DOS IDE, change to the \BP\EXAMPLES\DOS\TVFM directory
  18.   (use File|Change dir).
  19.  
  20.   This will enable the compiler to find all of the units used by
  21.   this program.
  22. }
  23.  
  24. const
  25. {$IFDEF SingleExe}
  26.   RezExt = '.EXE';
  27. {$ELSE}
  28.   RezExt = '.TVR';
  29. {$ENDIF}
  30.  
  31. type
  32.  
  33.   TMyApp = object(TApplication)
  34.     TrashCan: PTrashCan;
  35.     ExitDir: String;
  36.     constructor Init;
  37.     destructor Done; virtual;
  38.     procedure Idle; virtual;
  39.     procedure InitMenuBar; virtual;
  40.     procedure InitStatusLine; virtual;
  41.     procedure ToggleVideoMode;
  42.     procedure HandleEvent(var Event: TEvent); virtual;
  43.     procedure OutOfMemory; virtual;
  44.   end;
  45.  
  46.  
  47. { TMyApp implementation }
  48.  
  49. constructor TMyApp.Init;
  50. var
  51.   R: TRect;
  52.   H: Word;
  53.   CurDir: PathStr;
  54. begin
  55.   { Initialize resource file }
  56.  
  57.   RezStream := New(PProtectedStream, Init(GetExeBaseName + RezExt, stOpenRead, 4096));
  58.   if RezStream^.Status <> stOK then
  59.   begin
  60.     PrintStr('Unable to open resource file.');
  61.     Halt(1);
  62.   end;
  63.   RezFile.Init(RezStream);
  64.  
  65.   { Standard Turbo Vision objects }
  66.   RegisterObjects;
  67.   RegisterViews;
  68.   RegisterMenus;
  69.   RegisterDialogs;
  70.   RegisterApp;
  71.   RegisterStdDlg;
  72.  
  73.   { Objects specific to this app }
  74.   RegisterGlobals;
  75.   RegisterType(RStringList);
  76.   RegisterAssociations;
  77.  
  78.   RezStrings := PStringList(RezFile.Get('Strings'));
  79.  
  80.   if RezStrings = nil then
  81.   begin
  82.     PrintStr('Unable to read resources from resource file.');
  83.     Halt(1);
  84.   end;
  85.  
  86.   inherited Init;
  87.   InitAssociations;
  88.  
  89.   Desktop^.GetExtent(R);
  90.   Dec(R.B.Y); Inc(R.A.X);
  91.   R.A.Y := R.B.Y - 3;
  92.   R.B.X := R.A.X + 5;
  93.   TrashCan := New(PTrashCan, Init(R));
  94.   Desktop^.Insert(TrashCan);
  95.  
  96.   ConfigRec.Video := ScreenMode and smFont8x8;
  97.   ReadConfig;
  98.   if ConfigRec.Video <> (ScreenMode and smFont8x8) then
  99.     ToggleVideoMode;
  100.  
  101.   { by defaut, open a directory window to the current drive }
  102.   GetDir(0, CurDir);
  103.   InsertTreeWindow(CurDir[1]);
  104. end;
  105.  
  106. destructor TMyApp.Done;
  107. begin
  108.   DoneAssociations;
  109.   Dispose(TrashCan, Done);
  110. {$I-}
  111.   if ExitDir <> '' then
  112.   begin
  113.     if ExitDir[Length(ExitDir)] = ':' then ExitDir := ExitDir + '\';
  114.     ChDir(ExitDir);
  115.   end;
  116. {$I+}
  117.   inherited Done;
  118.   DoneMemory;
  119. end;
  120.  
  121. procedure TMyApp.Idle;
  122. const
  123.   FileListCmds : TCommandSet =
  124.     [cmExecute, cmViewAsHex, cmViewAsText, cmViewCustom, cmCopy, cmDelete,
  125.      cmRename, cmChangeAttr, cmReverseTags, cmClearTags, cmTagPerCard,
  126.      cmAssociate];
  127. var
  128.   TopWindow: PWindow;
  129. begin
  130.   inherited Idle;
  131.  
  132.   TopWindow := Message(Desktop, evBroadcast, cmTopWindow, nil);
  133.   if TopWindow = nil then
  134.   begin
  135.     DisableCommands(FileListCmds);
  136.     DisableCommands([cmExitHere]);
  137.   end
  138.   else
  139.   begin
  140.     EnableCommands([cmExitHere]);
  141.     if Message(TopWindow, evBroadcast, cmFileListFocused, nil) <> nil then
  142.       EnableCommands(FileListCmds)
  143.     else
  144.       DisableCommands(FileListCmds);
  145.   end;
  146.  
  147.   { This app defines a new type of event, evIdle.  This event type is }
  148.   { generated once every idle cycle.                                  }
  149.   Message(Desktop, evIdle, 0, nil);
  150. end;
  151.  
  152. procedure TMyApp.InitMenuBar;
  153. begin
  154.   MenuBar := PMenuBar(RezFile.Get('MainMenu'));
  155. end;
  156.  
  157. procedure TMyApp.InitStatusLine;
  158. var
  159.   R: TRect;
  160. begin
  161.   StatusLine := PHCStatusLine(RezFile.Get('StatusLine'));
  162.   GetExtent(R);
  163.   R.A.Y := R.B.Y - 1;
  164.   StatusLine^.Locate(R);
  165. end;
  166.  
  167. procedure TMyApp.ToggleVideoMode;
  168. var
  169.   NewMode: Word;
  170.   R: TRect;
  171. begin
  172.   NewMode := ScreenMode xor smFont8x8;
  173.   if NewMode and smFont8x8 <> 0 then ShadowSize.X := 1
  174.   else ShadowSize.X := 2;
  175.   SetScreenMode(NewMode);
  176.   Desktop^.GetExtent(R);
  177.   TrashCan^.Reposition(R);
  178.   ConfigRec.Video := ScreenMode and smFont8x8;
  179. end;
  180.  
  181. procedure TMyApp.HandleEvent(var Event: TEvent);
  182. var
  183.   NewDrive: Char;
  184. begin
  185.   inherited HandleEvent(Event);
  186.   if Event.What = evCommand then
  187.   begin
  188.     case Event.Command of
  189.       cmNewWindow:
  190.         begin
  191.           NewDrive := SelectDrive;
  192.           if NewDrive <> ' ' then InsertTreeWindow(NewDrive);
  193.           ClearEvent(Event);
  194.         end;
  195.       cmBeginSearch: BeginSearch;
  196.       cmInstallViewer : InstallViewer;
  197.       cmDisplayOptions : SetDisplayPrefs;
  198.       cmSaveConfig : SaveConfig;
  199.       cmTile : Tile;
  200.       cmCascade : Cascade;
  201.       cmCloseAll: Message(Desktop, evBroadcast, cmCloseAll, nil);
  202.       cmDosShell : DosShell;
  203.       cmRun : RunDosCommand('');
  204.       cmVideoMode: ToggleVideoMode;
  205.       cmExitHere:
  206.         begin
  207.           Message(Desktop, evBroadcast, cmGetCurrentDir, @ExitDir);
  208.           EndModal(cmQuit);
  209.           ClearEvent(Event);
  210.         end;
  211.       cmColorChange: SelectNewColors;
  212.     end;
  213.   end;
  214. end;
  215.  
  216. procedure TMyApp.OutOfMemory;
  217. begin
  218.   MessageBox('There is not enough memory to complete this operation.',
  219.     nil, mfError+mfOKButton);
  220. end;
  221.  
  222. var
  223.   MyApp : TMyApp;
  224.  
  225. begin
  226.   MyApp.Init;
  227.   MyApp.Run;
  228.   MyApp.Done;
  229. end.
  230.